// store/modules/user.js
import {
	getGlobalInfo
} from "@/api/common.js"
const state = () => ({
	appInfo: null
});

const mutations = {
	SET_APP_INFO(state, appInfo) {
		state.appInfo = appInfo;
		uni.setStorageSync('APP_INFO', appInfo)
	},
};

const actions = {
	async setAppInfo({
		commit,
		state
	}) {
		if (state.appInfo) return
		const data = await getGlobalInfo()
		commit('SET_APP_INFO', data)
	}
};

const getters = {
	getAppInfo: (state) => {
		return state.appInfo || uni.getStorageSync('APP_INFO')
	}
};

export default {
	namespaced: true, // 关键点！使用命名空间
	state,
	mutations,
	actions,
	getters
};